import React from 'react';
import dynamic from 'dva/dynamic';
import { Route } from 'dva/router';
import { isToken } from '../utils/judgmentEquipment.js'

export default function orderRoute(app) {
    const Login = dynamic({
      app,
      models: () => {
        return [
          import(/* webpackChunkName: "loginModel" */'../models/login/loginModel'),
        ];
      },
      component: () => import(/* webpackChunkName: "login" */'../routes/login/login'),
    });

    const order = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "orderModel" */'../models/order/orderModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "order" */'../routes/order/order'),
    });
    const MerchBill = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "orderModel" */'../models/order/orderModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "merchbill" */'../routes/order/MerchBill'),
    });
    const Address = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "addressModel" */'../models/order/addressModel'),
                import(/* webpackChunkName: "orderModel" */'../models/order/orderModel')
            ];
        },
        component: () => import(/* webpackChunkName: "orderaddress" */'../routes/order/address'),
    });

    const AddressAdd = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "addressModel" */'../models/order/addressModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "orderaddressadd" */'../routes/order/addressAdd'),
    });
    const EditAddress = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "editAddressModel" */'../models/order/addressModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "orderaddressedit" */'../routes/order/addressEdit'),
    });

    const Invoice = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "invoiceModel" */'../models/order/orderModel'),
                import(/* webpackChunkName: "balanceModel" */'../models/balance/balanceModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "orderaddressinvoice" */'../routes/order/invoice'),
    });
    const SelectInvoice = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "invoiceModel" */'../models/order/orderModel'),
                import(/* webpackChunkName: "balanceModel" */'../models/balance/balanceModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "orderaddressinvoice" */'../routes/order/selectInvoice'),
    });

    const Coupon = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "couponModel" */'../models/order/orderModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "ordercoupon" */'../routes/order/coupon'),
    });
    const PayType = dynamic({
        app,
        models: () => {
            return [
                import(/* webpackChunkName: "payTypeModel" */'../models/order/orderModel'),
            ];
        },
        component: () => import(/* webpackChunkName: "orderpaytype" */'../routes/order/paytype'),
    });

    return (
        [
            <Route key="/order" exact strict path="/order" component={order}/>,
            <Route key="/merchbill" exact strict path="/merchbill" component={MerchBill}/>,
            <Route key="/orderAddress" exact strict path="/orderAddress" children={(props) => isToken() ? <Address {...props}/>  : <Login {...props} /> }/>,
            <Route key="/orderAddressAdd" exact strict path="/orderAddressAdd" component={AddressAdd}/>,
            <Route key="/editOrderAddress" exact strict path="/editOrderAddress/:id" component={EditAddress}/>,
            <Route key="/selectInvoice" exact strict path="/selectInvoice/:storeId" component={SelectInvoice}/>,
            <Route key="/orderInvoice" exact strict path="/orderInvoice/:storeId" component={Invoice}/>,
            <Route key="/orderCoupon" exact strict path="/orderCoupon" component={Coupon}/>,
            <Route key="/orderPayType" exact strict path="/orderPayType" component={PayType}/>
        ]
    );
}
